package com.mego.megoandroid.database.manager;


import com.mego.megoandroid.activitys.AppContext;
import com.mego.megoandroid.database.dbmodel.SystemAllInfo;
import com.mego.megoandroid.database.greendao.SystemAllInfoDao;

import java.util.ArrayList;

//SystemAllInfo cc = SystemCenter.getInstance().getSysInfo("CCID");

public class SystemCenter {

    private static SystemCenter instance = new SystemCenter();

    public static SystemCenter getInstance() {
        return instance;
    }

    public SystemAllInfo getSysInfo(String key) {
        if (key == null || key.length() < 1) {
            return null;
        }
        String strContent = "";
        SystemAllInfo sInfo = null;
        try {
            SystemAllInfoDao systemAllInfoDao = AppContext.getInstances().getDaoSession().getSystemAllInfoDao();
            ArrayList<SystemAllInfo> sysList = new ArrayList<SystemAllInfo>();
            sysList = (ArrayList) systemAllInfoDao.queryBuilder()
                    .where(SystemAllInfoDao.Properties.Name.eq(key))
                    .build().list();
            if (sysList.size() > 0) {
                sInfo = sysList.get(0);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return sInfo;
    }

    //da4320
    public Long saveSysInfo(SystemAllInfo info) {
        if (info == null) {
            return 0L;
        }
        try {
            SystemAllInfoDao systemAllInfoDao = AppContext.getInstances().getDaoSession().getSystemAllInfoDao();
            long id = systemAllInfoDao.insertOrReplace(info);
            return id;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return 0L;
    }


}
